<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: shopmapmark.inc.php 4511 2010-09-19 00:51:25Z yumiao $
 */

if(!defined('IN_ADMIN')) {
	exit('Acess Denied');
}

require_once(B_ROOT.'./source/adminfunc/tool.func.php');

$operation = trim($_POST['operation']);
$resolved = intval($_REQUEST['resolved']);

if($resolved) {
	$selected[1] = 1;
	$wheresql = 'WHERE status=1';
} else {
	$selected[0] = 1;
	$wheresql = 'WHERE status=0';
}

if(!ckfounder($_G['uid'])) {
	$query = DB::query("SELECT itemid FROM ".DB::table("shopitems")." WHERE catid IN (".$_SGLOBAL['adminsession']['cpgroupshopcats'].")");
	while($result = DB::fetch($query)) {
		$shopitems[] = $result['itemid'];
	}
	if(!empty($shopitems)) {
		$wheresql .= ' AND itemid IN ('.implode(",", $shopitems).')';
	} else {
		$wheresql .= ' AND itemid IN (0)';
	}
}

shownav('infomanage', 'menu_shopmapmark');
showsubmenu('menu_shopmapmark', array(
	array('mod_notresolved', 'shopmapmark', $selected[0]),
	array('mod_resolved', 'shopmapmark&resolved=1', $selected[1])
));

if(submitcheck('deletesubmit')) {

	if(empty($_POST['shopmapmark'])) {
		cpmsg('notselect_item');
	}

	$shopmapmarks = implode(',', $_POST['shopmapmark']);
	if($operation == 'delete') {
		DB::query("DELETE FROM ".DB::table('shopmapmarks')." WHERE smmid IN ($shopmapmarks)");
	} elseif($operation == 'audit') {
		DB::query("UPDATE ".DB::table("shopmapmarks")." SET `status` = 1 WHERE smmid IN ($shopmapmarks)");
		foreach($_POST['shopmapmark'] as $smmid) {
			$shopmapmark = DB::fetch_first("SELECT itemid, mapapimark FROM ".DB::table('shopmapmarks')." WHERE smmid='$smmid';");
			updatetable('shopmessage', array('mapapimark'=>$shopmapmark['mapapimark']), array('itemid'=>$shopmapmark['itemid']));
			$_BCACHE->deltype('detail', 'shop', $shopmapmark['itemid']);
		}
	} else {
		cpmsg('operation_mustselected');
	}
	cpmsg('message_success', 'admin.php?action=shopmapmark&resolved='.$resolved);
}

$shopmapmark = $shopmapmarkarr = array();
$tpp = 12;
$page = $_GET['page'] > 0 ? intval($_GET['page']) : 1;
$rstart = ($page - 1) * $tpp;
$query = DB::query("SELECT COUNT(itemid) AS count  FROM ".DB::table('shopmapmarks')." $wheresql;");
$value = DB::fetch($query);
$multipage = multi($value['count'], $tpp, $page, 'admin.php?action=shopmapmark', $phpurl=1);
$query = DB::query("SELECT * FROM ".DB::table('shopmapmarks')." $wheresql ORDER BY dateline DESC LIMIT ".$rstart.", ".$tpp.";");

require_once(B_ROOT.'./source/adminfunc/list_photo.func.php');
$shopmapmarklist .= "<div id=\"pList_0\" act=\"pList\" style=\"margin-top:10px;\"><ul class=\"impressList clear\"> ";

$i = 0;
while($shopmapmark = DB::fetch($query)) {
	$shopmapmark['shopname'] = DB::result_first("SELECT subject FROM ".DB::table('shopitems')." WHERE itemid='$shopmapmark[itemid]'");
	$shopmapmark['shortshopname'] = cutstr($shopmapmark['shopname'], 15, 1);
	$shopmapmark['shortusername'] = cutstr($shopmapmark['username'], 16, 1);
	$shopmapmark['time'] = sgmdate($shopmapmark['dateline'], 'Y-m-d H:i:s');
	$shopmapmarklist .= showlistrowmark($shopmapmark);
	$i ++;
}
$shopmapmarklist .= "</ul></div>";
showformheader('shopmapmark');
echo '<div id="photo_list">
	<script src="http://ditu.google.cn/maps/api/js?sensor=false&language=zh-CN" type="text/javascript" charset="utf-8"></script>
';
echo $shopmapmarklist;
echo '<div style="clear:both;"><table><tr><td style="width:30px;vertical-align:middle;height:25px;"><input style="float:left;" type="checkbox" name="chkall" onclick="checkall(this.form, \'shopmapmark\')" checked/></td><td style="width:30px;vertical-align:middle;height:30px;">'.lang('selectall').'</td><td id="pagetd" style="width:500px;vertical-align:middle;">'.$multipage.'</td></tr></table></div></div>';

showtableheader(lang('operation_form'), 'nobottom');
if(!$resolved) {
	showtablerow('', array('width="50px"', ''), array(
				'<input class="radio" type="radio" name="operation" value="audit">',
				lang('shopmapmark_audited')
	));
}
showtablerow('', array('width="50px"', ''), array(
			'<input class="radio" type="radio" name="operation" value="delete"><input type="hidden" name="page" value="'.$_GET['page'].'"><input type="hidden" name="resolved" value="'.$resolved.'">',
			lang('mod_delete'),
));
showsubmit('deletesubmit', 'submit', '');
showtablefooter();
showformfooter();
showformfooter();
echo "
	<style>
		.impressList { color:#999; }
		.impressList li {
			float: left; overflow: hidden; height:280px; width: 24.5%; overflow:hidden; list-style-type: none;
		}
		.impressList li div.b {
			border-color: #A5C4FF;
			border-style: solid;
			border-width: 1px;
			height: 165px;
			padding: 6px 6px 9px;
			width: 230px;
			overflow:hidden;
		}
		#pagetd .pages{ margin-top:10px; }
	</style>";
bind_ajax_form();
?>